package com.hongxun.modules.bss.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.hongxun.common.validator.ValidatorUtils;
import com.hongxun.common.validator.group.AddGroup;
import com.hongxun.common.validator.group.UpdateGroup;
import com.hongxun.modules.bss.service.APBaseService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.hongxun.modules.bss.entity.ABatchEntity;
import com.hongxun.modules.bss.service.ABatchService;
import com.hongxun.common.utils.PageUtils;
import com.hongxun.common.utils.Query;
import com.hongxun.common.utils.R;




/**
 * 项目批次表
 * 
 * @author zkcn
 * @email youeremail@163.com
 * @date 2018-08-01 14:54:33
 */
@RestController
@RequestMapping("/bss/abatch")
public class ABatchController {
	@Autowired
	private ABatchService aBatchService;
	@Autowired
	private APBaseService aPBaseService;
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("bss:abatch:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
        String wheres =" 1=1 ";
        query.put("filterSql",wheres+" ");
		List<ABatchEntity> aBatchList = aBatchService.queryList(query);
		int total = aBatchService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(aBatchList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}

	@RequestMapping("/select")
    public R select(@RequestParam Map<String, Object> params){
		//查询列表数据
		Query query = new Query(params);
		String wheres =" 1=1 ";
		query.put("filterSql",wheres+" ");
		List<ABatchEntity> aBatchList = aBatchService.queryList(query);
       return R.ok().put("aBatchList", aBatchList);
	}

	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{guid}")
	@RequiresPermissions("bss:abatch:info")
	public R info(@PathVariable("guid") String guid){
		ABatchEntity aBatch = aBatchService.queryObject(guid);
		
		return R.ok().put("aBatch", aBatch);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("bss:abatch:save")
	public R save(@RequestBody ABatchEntity aBatch){
		aBatchService.save(aBatch);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("bss:abatch:update")
	public R update(@RequestBody ABatchEntity aBatch){
		aBatchService.update(aBatch);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("bss:abatch:delete")
	public R delete(@RequestBody String[] guids){
		for(String isd :guids)
		{
			Map<String ,Object> mapapole= new HashMap<>();
			String polewheres =" 1=1 ";
			polewheres+=" and  b_guid = '" + isd+"' ";
			polewheres+=" and  p_b_datastate!= '删除' ";
			mapapole.put("filterSql",polewheres+" ");
			int tole = aPBaseService.queryTotal(mapapole);
			if(tole==0)
			{
				String[] gusid =new String[]{isd};
				aBatchService.deleteBatch(gusid);
			}

		}
		return R.ok();
		

	}
	
}
